import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace BookingResourceRequirementApi {
  /** 资源需求信息 */
  export interface BookingResourceRequirement {
    id: number; // 主键ID
    bookingOrderId?: number; // 预约订单ID
    orderDetailId?: number; // 订单明细ID
    requirementCode?: string; // 需求编码
    resourceType?: string; // 资源类型
    resourceCategory?: string; // 资源分类
    resourceId: number; // 资源ID（可为空，表示任意资源）
    resourceName: string; // 资源名称
    resourceCode: string; // 资源编码
    requiredQuantity?: number; // 需求数量
    requiredDuration?: number; // 需求时长(分钟)
    requiredStartTime?: string | Dayjs; // 需求开始时间
    requiredEndTime?: string | Dayjs; // 需求结束时间
    constraintRules: string; // 约束规则
    preferenceRules: string; // 偏好规则
    exclusionRules: string; // 排除规则
    lockStatus?: string; // 锁定状态
    lockTime: string | Dayjs; // 锁定时间
    lockUserId: number; // 锁定操作人ID
    lockNotes: string; // 锁定备注
    allocationStatus?: string; // 分配状态
    allocationTime: string | Dayjs; // 分配时间
    allocationUserId: number; // 分配操作人ID
    allocatedResourceId: number; // 分配的资源ID
    allocatedResourceName: string; // 分配的资源名称
    allocationNotes: string; // 分配备注
    deliveryStatus?: string; // 交付状态
    deliveryTime: string | Dayjs; // 交付时间
    deliveryUserId: number; // 交付操作人ID
  }
}

/** 查询资源需求分页 */
export function getBookingResourceRequirementPage(params: PageParam) {
  return requestClient.get<PageResult<BookingResourceRequirementApi.BookingResourceRequirement>>('/spa/booking-resource-requirement/page', { params });
}

/** 查询资源需求详情 */
export function getBookingResourceRequirement(id: number) {
  return requestClient.get<BookingResourceRequirementApi.BookingResourceRequirement>(`/spa/booking-resource-requirement/get?id=${id}`);
}

/** 新增资源需求 */
export function createBookingResourceRequirement(data: BookingResourceRequirementApi.BookingResourceRequirement) {
  return requestClient.post('/spa/booking-resource-requirement/create', data);
}

/** 修改资源需求 */
export function updateBookingResourceRequirement(data: BookingResourceRequirementApi.BookingResourceRequirement) {
  return requestClient.put('/spa/booking-resource-requirement/update', data);
}

/** 删除资源需求 */
export function deleteBookingResourceRequirement(id: number) {
  return requestClient.delete(`/spa/booking-resource-requirement/delete?id=${id}`);
}


/** 导出资源需求 */
export function exportBookingResourceRequirement(params: any) {
  return requestClient.download('/spa/booking-resource-requirement/export-excel', { params });
}

